-module(fun_as_para).
-export([start/1]).
-define(SERVER_APPS, [sasl]).

manage_applications(Do,Undo,SkipError,ErrorTag,Apps)->
	lists:foldl(
			fun(App,Acc)->
				case Do(App) of
					ok -> [App|Acc];
					{error, {SkipError, _}} -> Acc;
					{error, Reason} ->
						lists:foreach(Undo, Acc),
						throw({error, {ErrorTag, App, Reason}})
				end
			end,[],Apps),
	ok.

start_applications(Apps)->
	manage_applications(fun application:start/1,
						fun application:stop/1,
						already_started,
						cannot_start_application,
						Apps).
						
stop_applications(Apps)->
	manage_applications(fun application:stop/1,
						fun application:start/1,
						not_started,
						cannot_stop_application,
						Apps).						

						
	
